package com.zjc.app.api.sdk.dto;

import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName;

public class ResultDto<T> {

    public static final String SUCCESS_CODE = "0000";

    /**
     * 返回码
     */
    private String code;
    /**
     * 返回消息
     */
    @SerializedName("msg")
    private String message;
    /**
     * 返回数据
     */
    private T data;

    public boolean isSuccess(){
        return SUCCESS_CODE.equals(this.code);
    }

    public boolean isFailure(){
        return !isSuccess();
    }

    private String getDataJsonStr() {
        return new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create().toJson(data);
    }

    private String toJsonStr() {
        return new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create().toJson(this);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
